<?php 
class Activity extends MX_Controller {

    private $table_name_path = 'activity';
    private $table_name = 'thĂ´ng tin hoáº¡t Ä‘á»™ng';

    public function __construct() {
        parent::__construct();
        $this->my_layout->setLayout("layout/frontend");
        //$this->load->helper('url');
        $this->load->helper(array("url",'form'));
        $this->load->library('form_validation');
        $this->load->library('pagination');
        $this->load->model('activity_model');
        $this->load->library('session');
        $this->load->model('center_model');
    }

    public function index($ItemNumber =0) {
        /*$activity = $this->activity_model->load_activity();
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        $config['base_url'] = base_url() . 'index.php/website/activity/index';
        $config['total_rows'] = $this->activity_model->load_activity()->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $data['link'] = $this->pagination->create_links();
        if($activity->num_rows()==0)
        {
          $data['notice']="Không có hoạt động nào!";
          $data['activity']=$activity->result_array();
          $this->my_layout->view("frontend/activity/list_activity_view", $data);
        }
        else{
        $data['notice']=null;
        $data['activity']= $activity->result_array();
        $this->my_layout->view("frontend/activity/list_activity_view", $data);
        }
        */
        $activity = $this->activity_model->load_activity('5',$ItemNumber);
        $data['activity'] = NULL;

        if ($activity->num_rows()>0){
            $data['activity'] = $activity->result_array();
            $data['notice'] = null;
        }else{
            $data['notice'] = 'Không tìm thấy tin tức nào';
        }
        //pageination
        $config['base_url'] = base_url() . 'index.php/website/activity/index';
        $config['total_rows'] = $this->activity_model->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $data['link'] = $this->pagination->create_links();
        
        //load center menu
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        
        $this->my_layout->view('frontend/activity/list_activity_view',$data);
        
    }

    function add_comment() {

        $this->load->library('form_validation');
        // Load data of current user
        $session_data = $this->session->userdata('logged_in');

        //set message
        $this->form_validation->set_message('required', "%s không được để trống.");
        $this->form_validation->set_rules('comment', 'Trả lời', 'trim|required|xss_clean');
        if ($this->form_validation->run($this) == TRUE) {
            // Add data to variable '$data'
            $comment = $this->input->post('comment');
            $id_activity = $this->input->post('id_activity');
            $id_user = $session_data['id'];

            // Call function create_comment in model 
            $this->load->model('comment_activity_model');
            echo $this->comment_activity_model->addComment($id_activity,$id_user,$comment);

            // Run action show_id to see new comment (refresh)   
        }
    }
     

    function load_by_id($id) {
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        $activity = $this->activity_model->get_by_id($id);
        $view = $activity['view'];
        $this->activity_model->increase_view($view,$id);
        $data['activity'] = $this->activity_model->get_by_id($id);      
		$this->load->model('comment_activity_model');
        $data['comment'] = $this->comment_activity_model->loadComment($id)->result_array();
        $data['listActForCenter'] = $this->activity_model->getActivitiesCenter($data['activity']['id_center']);
        $this->my_layout->view('frontend/activity/activity_view',$data);
    }
    function load_by_type($id_type)
    {

       $activity = $this->activity_model->get_by_type($id_type);
        $data['activity'] = NULL;
        if ($activity->num_rows()>0){
            $data['activity'] = $activity->result_array();
            $data['notice'] = null;
        }else{
            $data['notice'] = 'Không có hoạt động nào!';
        }
        
        //pageination
        $config['base_url'] = base_url() . 'index.php/website/activity/load_by_type/'.$id_type.'/';
        $config['total_rows'] = $this->activity_model->get_by_type($id_type)->num_rows();
        $config['per_page'] = 5;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);

        $data['link'] = $this->pagination->create_links();
        
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = $id_type;
        
        $this->my_layout->view('frontend/activity/list_activity_view',$data);
    }
    function load_by_id_of_center($id) {
        $data['type_of_center'] = $this->center_model->get_type();
        $data['idType'] = NULL;
        $data['activity'] = $this->activity_model->get_by_id($id);   
        $this->my_layout->view('frontend/activity/activity_view',$data);
    }

}

?>
